<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

//根路由直接跳转到 前台
Route::get('/', 'HomeController@index');
Route::get('/lists/{id}', 'HomeController@lists');
Route::get('/show/{id}', 'HomeController@show');
Route::post('search', 'HomeController@search');
Route::post('comment', 'HomeController@comment') ;


//登录处理===============//
Route::get('login', ['as'=>'login', function(){
    return View::make('login') ;
}]) ;

Route::post('login', function(){
    $creden = [
        'username' => Input::get('username') ,
        'password' => Input::get('password'),
    ] ;
    if (Auth::attempt($creden)){
        return Redirect::to('admin');
    }else{
		echo '输出错误信息！' ;
	}
    return Redirect::to('login') ;
}) ;

Route::get('logout', array('as' => 'logout', function () {
    Auth::logout() ;
    return Redirect::to('/') ;
}));
//登录处理===============\\

//后台应用
Route::group(['prefix'=>'admin','before' => 'auth'], function(){

    Route::resource('/', 'Admin\IndexController');
    Route::resource('post', 'Admin\PostController');
    Route::resource('user', 'Admin\UserController');
    Route::resource('comment', 'Admin\CommentController');
    Route::resource('photo', 'Admin\PhotoController');
    Route::resource('posttype', 'Admin\PostTypeController');
    
}) ;


















